package com.goldman.base.common.sys.config.tomcat;

import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Gracefully shut down tomcat server
 *
 * @author Bin
 */
@Configuration
public class WebContainerShutdownConfig {

    @Bean
    public WebGracefulShutdown gracefulShutdown() {
        return new WebGracefulShutdown();
    }

    @Bean
    public ConfigurableServletWebServerFactory webServerFactory(WebGracefulShutdown gracefulShutdown) {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addConnectorCustomizers(gracefulShutdown);
        return factory;
    }

}